import React, { Component } from 'react';
import { Modal, Form, Input } from 'antd';

const FormItem = Form.Item;

class ListModal extends Component {
  constructor(props) {
    super(props);
    this.state = {
      visible: false,
    };
  }

  showModelHandler = e => {
    if (e) e.stopPropagation();
    this.setState({
      visible: true,
    });
  };

  hideModelHandler = () => {
    this.setState({
      visible: false,
    });
  };

  okHandler = () => {
    const { onOk } = this.props;
    this.props.form.validateFields((err, values) => {
      //console.log(values);
      if (!err) {
        onOk(values);
        this.hideModelHandler();
      }
    });
  };
  render() {
    const { children } = this.props;
    const { getFieldDecorator } = this.props.form;
    const { id, name, account, number, sex,tags,status} = this.props.record;
    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 14 },
    };
    return (
      <span>
        <span onClick={this.showModelHandler}>{children}</span>
        <Modal
          title="员工编辑"
          visible={this.state.visible}
          onOk={this.okHandler}
          onCancel={this.hideModelHandler}
        >
          <Form layout="horizontal" onSubmit={this.okHandler}>
            <FormItem {...formItemLayout} label="id">
              {getFieldDecorator('id', {
                initialValue: id,
              })(<Input />)}
            </FormItem>
            <FormItem {...formItemLayout} label="员工姓名">
              {getFieldDecorator('name', {
                initialValue:name,
              })(<Input />)}
            </FormItem>
            <FormItem {...formItemLayout} label="员工账号">
              {getFieldDecorator('account', {
                initialValue: account,
              })(<Input />)}
            </FormItem>
            <FormItem {...formItemLayout} label="员工工号">
              {getFieldDecorator('number', {
                initialValue: number,
              })(<Input />)}
            </FormItem>
            <FormItem {...formItemLayout} label="员工性别">
              {getFieldDecorator('sex', {
                initialValue: sex,
              })(<Input />)}
            </FormItem>
            <FormItem {...formItemLayout} label="在线系统">
              {getFieldDecorator('tags', {
                initialValue: tags,
              })(<Input />)}
            </FormItem>
            <FormItem {...formItemLayout} label="状态">
              {getFieldDecorator('status', {
                initialValue: status,
              })(<Input />)}
            </FormItem>
          </Form>
        </Modal>
      </span>
    );
  }
}

export default Form.create()(ListModal);
